#include "../console.h"
// windows only
#ifdef WIN_APP
#include <Windows.h>
#include <tchar.h>

ZH_NAMESPACE_BEGIN

Console* Singleton<Console>::ms_Singleton = NULL;

Console::Console(String strName) : m_pStdOutFile(NULL), m_pStdErrFile(NULL)
{
	AllocConsole();
	SetConsoleTitleA(strName.c_str());
	freopen_s(&m_pStdOutFile, "CONOUT$", "a+", stdout);
//	_tfreopen_s(&m_pStdErrFile, L"CONERR$", L"a+", stderr);
}

Console::~Console()
{
	if (m_pStdOutFile)
		fclose(m_pStdOutFile);
	if (m_pStdErrFile)
		fclose(m_pStdErrFile);

	FreeConsole();
}

ZH_NAMESPACE_END

#endif // WIN_APP
